{include file="public/header" /}
<style>
    .layui-form-pane .layui-form-label {
        text-align: right;
    }

    .layui-form-pane .layui-form-label em {
        display: inline-block;
        color: red;
    }

    #demo1 {
        height: 100px;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>编辑品牌</h5>
        </div>
        <div class="ibox-content">
            <div class="example-wrap">
                <div class="example">
                    <form action="" class="layui-form layui-form-pane">
                        <div class="layui-form-item">
                            <label class="layui-form-label">品牌名称<em>*</em></label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" name="brand_name" placeholder="请输入品牌名称"
                                       lay-verify="required" lay-verType="tips" value="{$item['brand_name']}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">Logo<em>*</em></label>
                            <div class="layui-input-block">
                                <input type="hidden" id="brand_logo" name="brand_logo" value="{$item['brand_logo']}"
                                       lay-verify="required" lay-verType="msg">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                                    <div class="layui-upload-list">
                                        {if condition="$item['brand_logo']"}
                                        <img class="layui-upload-img" id="demo1"
                                             src="/static/uploads/brand/{$item['brand_logo']}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                        {else/}
                                        <img class="layui-upload-img" id="demo1" src="/static/admin/images/no_img.jpg">
                                        {/if}
                                        <p id="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">品牌网址</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" name="brand_url" placeholder="请输入品牌名称"
                                       lay-verType="tips" value="{$item['brand_url']}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否推荐<em>*</em></label>
                            <div class="layui-input-block">
                                <input type="radio" name="brand_tui" value="1" title="是" {if condition="$item['brand_tui'] eq 1"}checked{/if}>
                                <input type="radio" name="brand_tui" value="0" title="否" {if condition="$item['brand_tui'] eq 0"}checked{/if}>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序<em>*</em></label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" name="brand_sort" value="{$item['brand_sort']|default=10}" min="1"
                                       placeholder="请输入品牌名称" lay-verify="required|number" lay-verType="tips">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">品牌描述</label>
                            <div class="layui-input-block">
                                <textarea name="brand_remark" class="layui-textarea" placeholder="请输入品牌名称" lay-verType="tips">{$item['brand_remark']}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="brand_id" value="{$item['brand_id']}">
                                <button type="submit" class="layui-btn" lay-submit lay-filter="brand_edit">
                                    <i class="fa fa-save"></i> 保存
                                </button>
                                <button type="button" class="layui-btn layui-btn-danger" onclick="history.go(-1);">
                                    <i class="fa fa-close"></i> 返回
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    var form = layui.form,upload = layui.upload;

    //LOGO上传
    var uploadInst = upload.render({
        elem: '#test1',
        url: "{:url('Upload/uploads')}",
        data:{path:'brand'},
        before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#demo1').attr('src', result); //图片链接（base64）
            });
        },
        done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg(res.msg);
            }else{
                //上传成功
                $('#brand_logo').val(res.data);
            }
        },
        error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });

    /**
     * 编辑品牌
     */
    form.on('submit(brand_edit)', function (data) {
        var param = data.field;
        var load = layer.load(2);
        $.post("{:url('brand_edit')}", param, function (result) {
            layer.close(load);
            if (result.code === 200) {
                layer.msg(result.msg, {time: 1500,icon:1},function () {
                    location.href = "{:url('product/brand')}";
                });
            }else{
                layer.msg(result.msg, {time: 1500,icon:2});
            }
        });
        return false;
    });

</script>
</body>
</html>